﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using easywork.Utils;

namespace OneBarCode
{
    public partial class FrmSetSerialNum : Form
    {
        public FrmSetSerialNum()
        {
            InitializeComponent();
        }

        private void FrmSetSerialNum_Load(object sender, EventArgs e)
        {
            textBox1.Text = SystemConfig.SerialNum;
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 0x20) e.KeyChar = (char)0;  //禁止空格键  
            if ((e.KeyChar == 0x2D) && (((TextBox)sender).Text.Length == 0)) return;   //处理负数  
            if (e.KeyChar > 0x20)
            {
                try
                {
                    double.Parse(((TextBox)sender).Text + e.KeyChar.ToString());
                }
                catch
                {
                    e.KeyChar = (char)0;   //处理非法字符  
                }
            }  
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length<7)
            {
                MessageBox.Show("请正确设置（注意位数为七位）！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            try
            {
                string strSqlTemp = string.Format("update SystemConfig set SerialNum='{0}'", textBox1.Text);
                DataBaseManager.executeNonQuery(strSqlTemp);
                SystemConfig.SerialNum = textBox1.Text;
                MessageBox.Show("操作成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception)
            {
                MessageBox.Show("操作失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
